package org.sbbs.tool;

public class SbbsAbstractExporter
    extends SbbsExporter {
    protected void generateCore() {
        // noinspection UnnecessaryUnboxing
      //  boolean genericCore = Boolean.valueOf( getProperties().getProperty( "genericcore" ) ).booleanValue();

        // generate sample-data.xml
        configureExporter( "ssh/dao/sample-data.ftl", "src/test/resources/{class-name}-sample-data.xml" ).start();

        // Encourage use of genericCore - less code to maintain!
        /*if ( genericCore ) {
            configureExporter( "ssh/service/generic-beans.ftl", "src/main/resources/{class-name}-generic-beans.xml" ).start();
        }
        else {*/
            // DAO Test
            configureExporter( "ssh/dao/dao-test.ftl", "src/test/java/{basepkg-name}/dao/{class-name}DaoTest.java" ).start();

            // DAO Interfaces
            configureExporter( "ssh/dao/dao.ftl", "src/main/java/{basepkg-name}/dao/{class-name}Dao.java" ).start();

            // DAO Bean Definition - only used when genericCore == true
            configureExporter( "ssh/dao/dao-bean.ftl", "src/main/resources/{class-name}Dao-bean.xml" ).start();

            String daoFramework = getProperties().getProperty( "daoframework" );

            // DAO Implementation
            configureExporter( "ssh/dao/" + daoFramework + "/dao-impl.ftl",
                               "src/main/java/{basepkg-name}/dao/" + daoFramework + "/{class-name}Dao" + getDaoFilename( daoFramework ) + ".java" ).start();

            // Manager Test
            configureExporter( "ssh/service/manager-test.ftl", "src/test/java/{basepkg-name}/service/impl/{class-name}ManagerImplTest.java" ).start();

            // Manager Interface
            configureExporter( "ssh/service/manager.ftl", "src/main/java/{basepkg-name}/service/{class-name}Manager.java" ).start();

            // Manager Implementation
            configureExporter( "ssh/service/manager-impl.ftl", "src/main/java/{basepkg-name}/service/impl/{class-name}ManagerImpl.java" ).start();
       // }

       // String daoFramework = getProperties().getProperty( "daoframework" );

        // Manager Bean Definition - only used when genericCore == true
       // configureExporter( "ssh/service/manager-bean.ftl", "src/main/resources/{class-name}Manager-bean.xml" ).start();
    }

    protected void generateWeb() {
        String packaging = getProperties().getProperty( "packaging" );
        boolean webProject = packaging != null && packaging.equalsIgnoreCase( "war" );

        if ( !webProject )
            return;

        String webFramework = getProperties().getProperty( "webframework" );
        String fType = getProperties().getProperty( "fType" );
        String pojoName = System.getProperty( "entity" );
        String detailFullPathName = getProperties().getProperty( "detailFullPathName" );
        if ( webFramework.equalsIgnoreCase( "struts" ) ) {

            /*
             * TODO 此处进行模板代码产出
             */
            // tests
             configureExporter("ssh/web/struts/action-test.ftl",
             "src/test/java/{basepkg-name}/webapp/action/{class-name}ActionTest.java").start();

            // controllers
            configureExporter( "ssh/web/struts/action.ftl", "src/main/java/{basepkg-name}/webapp/action/{class-name}PagedAction.java" ).start();
           // configureExporter( "ssh/web/struts/edit-action.ftl", "src/main/java/{basepkg-name}/webapp/action/{class-name}EditAction.java" ).start();
            // views
            if ( fType.equals( "2" ) && pojoName.equals( detailFullPathName ) ) {
                configureExporter( "ssh/web/struts/detailList-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}List.jsp" ).start();
            }
            else {
                configureExporter( "ssh/web/struts/list-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}List.jsp" ).start();
            }

            configureExporter( "ssh/web/struts/form-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}Form.jsp" ).start();

            // configuration
            // This template is not used anymore (APF-798), but retained in case we do want to create definitions by
            // default in the future
            // configureExporter("ssh/web/struts/action-beans.ftl",
            // "src/main/webapp/WEB-INF/{class-name}-struts-bean.xml").start();

            configureExporter( "ssh/web/struts/struts.ftl", "src/main/java/{basepkg-name}/webapp/struts_action_{class-name}.xml" ).start();

            // validation
            // configureExporter("ssh/web/struts/model-validation.ftl",
            // "src/main/resources/{basepkg-name}/model/{class-name}-validation.xml").start();
            // configureExporter("ssh/web/struts/action-validation.ftl",
            // "src/main/resources/{basepkg-name}/webapp/action/{class-name}Action-validation.xml").start();

        }
        else {
            log.warn( "Your project's web framework '" + webFramework + "' is not supported by AMP at this time." );
            log.warn( "See http://issues.appfuse.org/browse/EQX-211 for more information." );

        }

        // menu
        /*
         * configureExporter("ssh/web/menu.ftl", "src/main/webapp/common/{class-name}-menu.jsp").start();
         * configureExporter("ssh/web/menu-light.ftl",
         * "src/main/webapp/common/{class-name}-menu-light.jsp").start();
         * configureExporter("ssh/web/menu-config.ftl",
         * "src/main/webapp/WEB-INF/{class-name}-menu-config.xml").start();
         */

        // i18n
        configureExporter( "ssh/web/ApplicationResources.ftl", "src/main/java/{basepkg-name}/webapp/{class-name}-package.properties" ).start();

        // ui tests
        /*
         * if (!webFramework.equals("wicket") && !webFramework.equals("spring-security") &&
         * !webFramework.equals("spring-freemarker") && !webFramework.equals("stripes")) {
         * configureExporter("ssh/web/" + webFramework + "/web-tests.ftl",
         * "src/test/resources/{class-name}-web-tests.xml").start(); }
         */
    }
}
